<?php

/*
  +--------------------------------------------------------------------------
  |   Invision Power Board
  |   =============================================
  |   by Matthew Mecham
  |   (c) 2001 - 2006 Invision Power Services, Inc.
  |
  |   =============================================
  |
  |
  +---------------------------------------------------------------------------
  |   > $Date: 2007-12-27 14:32:48 -0500 (Thu, 27 Dec 2007) $
  |   > $Revision: 1151 $
  |   > $Author: bfarber $
  +---------------------------------------------------------------------------
  |
  |   > Post Sub-Class
  |   > Module written by Matt Mecham
  |   > Date started: Wednesday 9th March 2005 (15:23)
  |
  +--------------------------------------------------------------------------
 */

if (!defined('IN_IPB')) {
    print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
    exit();
}

class post_functions extends class_post {

    var $nav = array();
    var $title = "";
    var $post = array();
    var $upload = array();
    var $mod_topic = array();
    var $class = "";
    var $m_group = "";
    var $post_key = "";
    var $has_poll = 0;
    var $poll_questions = array();
    var $orig_post;

    /* ------------------------------------------------------------------------- */

    // Sub class init
    /* ------------------------------------------------------------------------- */

    function main_init() {
        //-----------------------------------------
        // Load classes
        //-----------------------------------------

        $this->load_classes();
        $this->build_permissions();

        //-----------------------------------------
        // Check permissions
        //-----------------------------------------

        $this->post_key = ( isset($this->ipsclass->input['attach_post_key']) AND $this->ipsclass->input['attach_post_key'] != "" ) ? $this->ipsclass->input['attach_post_key'] : md5(microtime());

        $this->check_for_new_topic();
    }

    /* ------------------------------------------------------------------------- */

    // MAIN PROCESS FUNCTION
    /* ------------------------------------------------------------------------- */

    function process_post() {
        //-----------------------------------------
        // Convert times...
        //-----------------------------------------
        
        $this->convert_open_close_times();

        //-----------------------------------------
        // Parse the post, and check for any errors.
        //-----------------------------------------

        $this->post = $this->compile_post();

        //-----------------------------------------
        // check to make sure we have a valid topic title
        //-----------------------------------------

        $this->ipsclass->input['TopicTitle'] = str_replace("<br />", "", $this->ipsclass->input['TopicTitle']);
        
        $this->ipsclass->input['TopicTitle'] = trim($this->ipsclass->input['TopicTitle']);
        //echo $this->ipsclass->input['TopicTitle']."aa";exit();
        //-----------------------------------------
        // More unicode..
        //-----------------------------------------

        $temp = $this->ipsclass->txt_stripslashes($_POST['TopicTitle']);

        if ($this->ipsclass->txt_mb_strlen($_POST['TopicTitle']) > $this->ipsclass->vars['topic_title_max_len']) {
            $this->obj['post_errors'] = 'topic_title_long';
        }

        if ((strlen($temp) < 2) or (!$this->ipsclass->input['TopicTitle'])) {
            $this->obj['post_errors'] = 'no_topic_title';
        }

        //-----------------------------------------
        // Compile the poll
        //-----------------------------------------

        $this->poll_questions = $this->compile_poll();

        if (($this->obj['post_errors'] != "") or ( $this->obj['preview_post'] != "" )) {
            //-----------------------------------------
            // Show the form again
            //-----------------------------------------

            $this->show_form();
        } else {
            //-----------------------------------------
            // Guest w/ CAPTCHA?
            //-----------------------------------------

            if ($this->ipsclass->member['id'] == 0 AND $this->ipsclass->vars['guest_captcha']) {
                //-----------------------------------------
                // Security code stuff
                //-----------------------------------------

                if ($this->ipsclass->input['imgid'] == "") {
                    $this->obj['post_errors'] = 'err_reg_code';
                    $this->show_form();
                    return;
                }

                $this->ipsclass->DB->simple_construct(array('select' => '*',
                    'from' => 'reg_antispam',
                    'where' => "regid='" . trim($this->ipsclass->txt_alphanumerical_clean($this->ipsclass->input['imgid'])) . "'"
                ));

                $this->ipsclass->DB->simple_exec();

                if (!$row = $this->ipsclass->DB->fetch_row()) {
                    $this->obj['post_errors'] = 'err_reg_code';
                    $this->show_form();
                    return;
                }

                if (trim($this->ipsclass->txt_alphanumerical_clean($this->ipsclass->input['captcha'])) != $row['regcode']) {
                    $this->obj['post_errors'] = 'err_reg_code';
                    $this->show_form();
                    return;
                }

                $this->ipsclass->DB->do_delete('reg_antispam', "regid='" . trim($this->ipsclass->txt_alphanumerical_clean($this->ipsclass->input['imgid'])) . "'");
            }

            $this->save_post();
        }
    }

    /* ------------------------------------------------------------------------- */

    // ADD TOPIC FUNCTION
    /* ------------------------------------------------------------------------- */

    function save_post() {
        //-----------------------------------------
        // Fix up the topic title
        //-----------------------------------------
        //var_dump($this->ipsclass->input);exit();
        $this->ipsclass->input['TopicDesc'] = trim($this->parser->bad_words($this->ipsclass->input['TopicDesc']));
        $this->ipsclass->input['TopicDesc'] = $this->ipsclass->txt_mbsubstr($this->ipsclass->input['TopicDesc'], 0, 70);

        if ($this->forum['is_private']) {
            $this->ipsclass->input['TopicPriv'] = 1;
        }

        if ($this->forum['is_buddy_box']) {
            $this->ipsclass->input['is_buddy'] = 1;
        }

        $pinned = 0;
        $state = 'open';

        $this->ipsclass->input['mod_options'] = isset($this->ipsclass->input['mod_options']) ? $this->ipsclass->input['mod_options'] : '';

        if (($this->ipsclass->input['mod_options'] != "") or ($this->ipsclass->input['mod_options'] != 'nowt')) {
            if ($this->ipsclass->input['mod_options'] == 'pin') {
                if ($this->ipsclass->member['g_is_supmod'] == 1 or $this->moderator['pin_topic'] == 1) {
                    $pinned = 1;

                    $this->moderate_log($this->ipsclass->lang['modlogs_pinned'], $this->ipsclass->input['TopicTitle']);
                }
            } else if ($this->ipsclass->input['mod_options'] == 'close') {
                if ($this->ipsclass->member['g_is_supmod'] == 1 or $this->moderator['close_topic'] == 1) {
                    $state = 'closed';

                    $this->moderate_log($this->ipsclass->lang['modlogs_closed'], $this->ipsclass->input['TopicTitle']);
                }
            } else if ($this->ipsclass->input['mod_options'] == 'pinclose') {
                if ($this->ipsclass->member['g_is_supmod'] == 1 or ( $this->moderator['pin_topic'] == 1 AND $this->moderator['close_topic'] == 1 )) {
                    $pinned = 1;
                    $state = 'closed';

                    $this->moderate_log($this->ipsclass->lang['modlogs_pinclose'], $this->ipsclass->input['TopicTitle']);
                }
            }
        }

        //-----------------------------------------
        // Check close times...
        //-----------------------------------------

        if ($state == 'open' AND ( $this->times['open'] OR $this->times['close'] )
                AND ( $this->times['close'] <= time() OR ( $this->times['open'] > time() AND !$this->times['close'] ) )) {
            $state = 'closed';
        }
        
        //get friend id
        require_once( ROOT_PATH . 'sources/action_public/Common.php' );
        $common = new Common();
        $common->ipsclass = & $this->ipsclass;
        $member = array();
        if(intval($this->ipsclass->input['profile_id'])){
            $member = $common->format_member(intval($this->ipsclass->input['profile_id']));
        }
        //var_dump($this->ipsclass->input);exit();
        //-----------------------------------------
        // Build the master array
        //-----------------------------------------
        if($member['id']){
            $this->topic = array(
                'title' => $this->ipsclass->input['TopicTitle'],
                'description' => $this->ipsclass->input['TopicDesc'],
                'private' => $this->ipsclass->input['TopicPriv'], // Private added by BabyWolf
                'is_buddy' => $this->ipsclass->input['is_buddy'], // Buddy property added by BabyWolf
                'state' => $state,
                'posts' => 0,
                'starter_id' => $member['id'],
                'starter_name' => $member['id'] ? $member['members_display_name'] : $member['name'],
                // Added by BabyWolf
                'starter_uname' => $member['id'] ? $member['name'] : $member['name'],
                'start_date' => time(),
                'last_poster_id' => $member['id'],
                'last_poster_name' => $member['id'] ? $member['members_display_name'] : $member['name'],
                // Added by BabyWolf
                'last_poster_uname' => $member['id'] ? $member['name'] : $member['name'],
                'last_post' => time(),
                'icon_id' => intval($this->ipsclass->input['iconid']),
                'author_mode' => $member['id'] ? 1 : 0,
                'poll_state' => ( count($this->poll_questions) AND $this->can_add_poll ) ? 1 : 0,
                'last_vote' => 0,
                'views' => 0,
                'forum_id' => $this->forum['id'],
                'approved' => ( $this->obj['moderate'] == 1 || $this->obj['moderate'] == 2 ) ? 0 : 1,
                'pinned' => $pinned,
                'topic_open_time' => intval($this->times['open']),
                'topic_close_time' => intval($this->times['close']),
            );
        }else{
            $this->topic = array(
                'title' => $this->ipsclass->input['TopicTitle'],
                'description' => $this->ipsclass->input['TopicDesc'],
                'private' => $this->ipsclass->input['TopicPriv'], // Private added by BabyWolf
                'is_buddy' => $this->ipsclass->input['is_buddy'], // Buddy property added by BabyWolf
                'state' => $state,
                'posts' => 0,
                'starter_id' => $this->ipsclass->member['id'],
                'starter_name' => $this->ipsclass->member['id'] ? $this->ipsclass->member['members_display_name'] : $this->ipsclass->input['UserName'],
                // Added by BabyWolf
                'starter_uname' => $this->ipsclass->member['id'] ? $this->ipsclass->member['name'] : $this->ipsclass->input['UserName'],
                'start_date' => time(),
                'last_poster_id' => $this->ipsclass->member['id'],
                'last_poster_name' => $this->ipsclass->member['id'] ? $this->ipsclass->member['members_display_name'] : $this->ipsclass->input['UserName'],
                // Added by BabyWolf
                'last_poster_uname' => $this->ipsclass->member['id'] ? $this->ipsclass->member['name'] : $this->ipsclass->input['UserName'],
                'last_post' => time(),
                'icon_id' => intval($this->ipsclass->input['iconid']),
                'author_mode' => $this->ipsclass->member['id'] ? 1 : 0,
                'poll_state' => ( count($this->poll_questions) AND $this->can_add_poll ) ? 1 : 0,
                'last_vote' => 0,
                'views' => 0,
                'forum_id' => $this->forum['id'],
                'approved' => ( $this->obj['moderate'] == 1 || $this->obj['moderate'] == 2 ) ? 0 : 1,
                'pinned' => $pinned,
                'topic_open_time' => intval($this->times['open']),
                'topic_close_time' => intval($this->times['close']),
            );
        }
        
        //var_dump($this->topic);exit();
        //-----------------------------------------
        // Insert the topic into the database to get the
        // last inserted value of the auto_increment field
        // follow suit with the post
        //-----------------------------------------

        $this->ipsclass->DB->force_data_type = array('title' => 'string',
            'description' => 'string',
            'starter_name' => 'string',
            // Added by BabyWolf
            'starter_uname' => 'string',
            'last_poster_name' => 'string',
            // Added by BabyWolf
            'last_poster_uname' => 'string');

        $this->ipsclass->DB->do_insert('topics', $this->topic);

        $this->post['topic_id'] = $this->ipsclass->DB->get_insert_id();
        $this->topic['tid'] = $this->post['topic_id'];

        
        
        // Process set home topic by BabyWolf
        // Check if this member is super moderator
        if ($this->ipsclass->member['g_is_supmod'] && $this->ipsclass->input['check_home_topic']) {
            $home_topic_query = "INSERT INTO " . $this->ipsclass->DB->obj['sql_tbl_prefix'] . "home_topics ";
            $home_topic_values = " VALUES ";

            // ({$dba['FIELD_NAMES']}) VALUES({$dba['FIELD_VALUES']})";
            $set_time = time();
            if (count($this->ipsclass->input['home_topic_sites']) > 0) {
                foreach ($this->ipsclass->input['home_topic_sites'] as $site_id) {
                    $home_topic_data = array('topic_id' => $this->topic['tid'],
                        'topic_site_id' => $site_id,
                        'topic_time' => $set_time
                    );

                    $dba = $this->ipsclass->DB->compile_db_insert_string($home_topic_data);
                    $home_topic_values .= "(" . $dba['FIELD_VALUES'] . "),";
                }

                $home_topic_query .= "(" . $dba['FIELD_NAMES'] . ") " . trim($home_topic_values, ",");
                $this->ipsclass->DB->query($home_topic_query);
            } else {
                $home_topic_data = array('topic_id' => $this->topic['tid'],
                    'topic_site_id' => 0,
                    'topic_time' => $set_time
                );
                $this->ipsclass->DB->do_insert('home_topics', $home_topic_data);
            }
        }

        //-----------------------------------------
        // Update the post info with the upload array info
        //-----------------------------------------

        $this->post['post_key'] = $this->post_key;
        $this->post['new_topic'] = 1;

        //-----------------------------------------
        // Unqueue the post if we're starting a new topic
        //-----------------------------------------

        $this->post['queued'] = 0;

        //-----------------------------------------
        // Add post to DB
        //-----------------------------------------

        $this->ipsclass->DB->do_insert('posts', $this->post);

        $this->post['pid'] = $this->ipsclass->DB->get_insert_id();

        //-----------------------------------------
        // Update topic with firstpost ID
        //-----------------------------------------

        $this->ipsclass->DB->simple_construct(array('update' => 'topics',
            'set' => "topic_firstpost=" . $this->post['pid'],
            'where' => "tid=" . $this->topic['tid']
        ));
        
        $this->ipsclass->DB->simple_exec();
        if(isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == 'diary'){
            $this->ipsclass->DB->simple_construct(array('update' => 'topics',
                'set' => "approved = 1" ,
                'where' => "tid=" . $this->topic['tid']
            ));
            $this->ipsclass->DB->simple_exec();
        }
        
        
        //setup product here
        $f_id = intval($this->forum['id']);
        if($f_id > 0){
            $this->ipsclass->DB->build_query( array('select' => 'f.parent_id',
                                                    'from'   => 'forums f',
                                                    'where'    => "f.id = {$f_id}"
                                                    ) 
                                            );
            $this->ipsclass->DB->exec_query();
            $row = $this->ipsclass->DB->fetch_row();
            //var_dump ($row);exit();
            if(count($row) > 0 && intval($row['parent_id']) == $this->ipsclass->vars['all_product_cat_id']){
                $this->product = array(
                    'product_id' => $this->topic['tid'],
                    'quantity' => $this->ipsclass->input['totalQuatity'],
                    'color' => $this->ipsclass->input['proColor'],
                    'price' => $this->ipsclass->input['proPrice'], 
                    'org_price' => $this->ipsclass->input['proOriPrice'],
                    'post_id' => $this->post['pid'],
                );
                $this->ipsclass->DB->do_insert('product_info', $this->product);
            }
        }
        
        //-----------------------------------------
        // Add the poll to the polls table
        //-----------------------------------------
//		if ( count( $this->poll_questions ) AND $this->can_add_poll )
//		{
//			$poll_only = 0;
//			
//			if( $this->ipsclass->vars['ipb_poll_only'] AND $this->ipsclass->input['poll_only'] == 1 )
//			{
//				$poll_only = 1;
//			}
//
//			$this->ipsclass->DB->do_insert( 'polls', 
//											array (
//													  'tid'           => $this->topic['tid'],
//													  'forum_id'      => $this->forum['id'],
//													  'start_date'    => time(),
//													  'choices'       => addslashes(serialize( $this->poll_questions )),
//													  'starter_id'    => $this->ipsclass->member['id'],
//													  'votes'         => 0,
//													  'poll_question' => $this->ipsclass->input['poll_question'],
//													  'poll_only'	  => $poll_only,
//											)     );
//		}
        //-----------------------------------------
        // If we are still here, lets update the
        // board/forum stats
        //----------------------------------------- 

        $this->pf_update_forum_and_stats($this->topic['tid'], $this->topic['title'], 'new');

        //-----------------------------------------
        // Make attachments "permanent"
        //-----------------------------------------

        $this->pf_make_attachments_permanent($this->post_key, $this->post['pid'], 'post', array('topic_id' => $this->topic['tid']));

        //-----------------------------------------
        // If we are a member, lets update thier last post
        // date and increment their post count.
        //-----------------------------------------

        $this->pf_increment_user_post_count();
        // Added by BabyWolf
        $this->Dkm_Topic_Process();
        $increase_cash = $this->ipsclass->vars['dkm_increase_cash_new'] ? $this->ipsclass->vars['dkm_increase_cash_new'] : 1;
        $this->Dkm_Cash_Process($increase_cash);

        //-----------------------------------------
        // Are we tracking new topics we start 'auto_track'?
        //-----------------------------------------

        $this->pf_add_tracked_topic($this->topic['tid']);

        //-----------------------------------------
        // Moderating?
        //-----------------------------------------

        if ($this->obj['moderate'] == 1 OR $this->obj['moderate'] == 2) {
            //-----------------------------------------
            // Redirect them with a message telling them the
            // post has to be previewed first
            //-----------------------------------------

            $this->notify_new_topic_approval($this->topic['tid'], $this->topic['title'], $this->topic['starter_name'], $this->post['pid']);
            if(isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == 'diary'){
                //$this->ipsclass->boink_it("{$this->ipsclass->vars['profile_url']}/{$this->ipsclass->member['name']}/?CODE=diaries");
                $id = $member['id'] ? $member['id'] : $this->ipsclass->member['id'];
                $this->ipsclass->boink_it("{$this->ipsclass->vars['profile_url']}/{$this->ipsclass->member['name']}/nhat-ky/{$id}.html");
            }else{
                $this->ipsclass->print->redirect_screen($this->ipsclass->lang['moderate_topic'], "act=SF&f={$this->forum['id']}");
                //$this->ipsclass->boink_it("http://google.com");

            }
            
        }

        //-----------------------------------------
        // Are we tracking this forum? If so generate some mailies - yay!
        //-----------------------------------------

        $this->forum_tracker($this->forum['id'], $this->topic['tid'], $this->topic['title'], $this->forum['name'], $this->post['post']);

        //-----------------------------------------
        // Redirect them back to the topic
        //-----------------------------------------
        // Require text code class for topic clean url
        // Added by BabyWolf
        require_once(KERNEL_PATH . "class_textcode.php");
        $this->ipsclass->textcode = new class_textcode();
        $username = $this->topic['starter_uname'] ? strtolower($this->topic['starter_uname']) : 'topic';
        $topic_clean_title = strtolower($this->ipsclass->textcode->RemoveAccent($this->topic['title'], "-"));

        // Added by BabyWolf
        if ($this->ipsclass->vars['board_url'] == $this->ipsclass->vars['profile_url']) {
            if ($this->ipsclass->input['f'] == 37)
                $this->topic['topic_url'] = $this->ipsclass->vars['board_url'] . "/" . $username . "/diaries/" . $topic_clean_title . "." . $this->topic['tid'];
            else
                $this->topic['topic_url'] = $this->ipsclass->vars['board_url'] . "/" . $username . "/topics/" . $topic_clean_title . "." . $this->topic['tid'];
        }
        else {
            $this->topic['topic_url'] = $this->ipsclass->vars['board_url'] . "/" . $username . "/" . $topic_clean_title . "." . $this->topic['tid'];
        }
        if(isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == 'diary'){
            $this->ipsclass->boink_it("{$this->ipsclass->vars['profile_url']}/{$this->ipsclass->member['name']}/?CODE=diaries");
        }else{
            $this->ipsclass->boink_it($this->topic['topic_url']);
        }
//        $this->ipsclass->boink_it($this->topic['topic_url']);
    }

    /* ------------------------------------------------------------------------- */

    // SHOW FORM
    /* ------------------------------------------------------------------------- */

    function show_form() {
        require_once( ROOT_PATH . 'sources/action_public/Common.php' );
        $common = new Common();
        $common->ipsclass = & $this->ipsclass;
        //-----------------------------------------
        // Are we quoting posts?
        //-----------------------------------------
        //var_dump($this->han_editor->method);exit();
        if ($this->han_editor->method != 'rte') {
            $_POST['Post'] = str_replace('&', '&amp;', $_POST['Post']);
        }
        //var_dump($_POST['Post']);exit();
        $raw_post = $this->check_multi_quote();

        //-----------------------------------------
        // RTE? Convert RIGHT tags that QUOTE would
        // have put there
        //-----------------------------------------
        //echo $this->han_editor->method;exit();
        if ($this->han_editor->method == 'rte') {
            $raw_post = $this->parser->convert_ipb_html_to_html($raw_post);
        }
        //var_dump($raw_post);exit();
        //-----------------------------------------
        // Sort out the "raw" textarea input and make it safe incase
        // we have a <textarea> tag in the raw post var.
        //-----------------------------------------
        
        $topic_title = isset($_POST['TopicTitle']) ? $this->ipsclass->input['TopicTitle'] : "";
        $topic_desc = isset($_POST['TopicDesc']) ? $this->ipsclass->input['TopicDesc'] : "";
        // Added private by BabyWolf
        $topic_private = isset($_POST['TopicPriv']) ? " checked" : "";
        
        //-----------------------------------------
        // Do we have any posting errors?
        //-----------------------------------------
         if (((isset($this->obj['post_errors']) AND $this->obj['post_errors']) || $this->obj['preview_post']) && isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == "diary") {
             //echo $this->output;exit();
             $this->output .= $common->load_left_content($this->ipsclass->member, TRUE, FALSE);
             $this->output .= "<div id='content-main'><div id='content'>";
         }
         
        if (isset($this->obj['post_errors']) AND $this->obj['post_errors']) {
            $this->nav = "abc";
            $this->page = "abc";
            $this->output .= $this->ipsclass->compiled_templates['skin_post']->errors($this->ipsclass->lang[$this->obj['post_errors']]);
            
            
        }

        if ($this->obj['preview_post']) {
            
            $this->output .= $this->ipsclass->compiled_templates['skin_post']->preview($this->show_post_preview($this->post['post'], $this->post_key));
        }
        //pumper forum setting new post
        //get current domain name
        $current_domain = "http://".$_SERVER['SERVER_NAME'];
        //check domain
        if($current_domain == $this->ipsclass->vars['forum_pumper_url']){
            $this->output .= $this->ipsclass->compiled_templates['skin_post']->div_start_top();
        }
        //var_dump($this->ipsclass->input);exit();
        $this->output .= $this->html_start_form(array(1 => array('CODE', '01'),
            2 => array('attach_post_key', $this->post_key),
        ));

        //-----------------------------------------
        // START TABLE
        //-----------------------------------------

        $this->output .= $this->ipsclass->compiled_templates['skin_post']->table_structure();
        //echo $this->output;exit();
        // Added Private by BabyWolf
        $start_table = $this->ipsclass->compiled_templates['skin_post']->table_top("{$this->ipsclass->lang['top_txt_new']} <span class='topic_title'>\"{$this->forum['name']}\"</span>");
        $topic_title = $this->ipsclass->compiled_templates['skin_post']->topictitle_fields(array('TITLE' => $topic_title, 'DESC' => $topic_desc, 'PRIVATE' => $topic_private));
        
        $name_fields = $this->html_name_field();

        $post_box = $this->html_post_body($raw_post);
        //echo($post_box);exit();
        $mod_options = $this->mod_options();
        //var_dump($this->ipsclass);
        //setup product info
        $f_id = intval($this->ipsclass->input['f']);
        if($f_id > 0){
            $this->ipsclass->DB->build_query( array('select' => 'f.parent_id',
                                                    'from'   => 'forums f',
                                                    'where'    => "f.id = {$f_id}"
                                                    ) 
                                            );
            $this->ipsclass->DB->exec_query();
            $row = $this->ipsclass->DB->fetch_row();
            //var_dump ($row);exit();
            if(count($row) > 0 && intval($row['parent_id']) == $this->ipsclass->vars['all_product_cat_id']){
                $end_form .= $this->ipsclass->compiled_templates['skin_post']->product_info($row['id']);
            }
        }
        $end_form .= $this->ipsclass->compiled_templates['skin_post']->EndForm($this->ipsclass->lang['submit_new']);
        if(isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == "diary"){
            $end_form .= "</div>";
        }
        if($current_domain == $this->ipsclass->vars['forum_pumper_url']){
            $this->output .= $this->ipsclass->compiled_templates['skin_post']->div_end_top();
        }
//        if (((isset($this->obj['post_errors']) AND $this->obj['post_errors']) || $this->obj['preview_post']) && isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == "diary") {
//             $this->output .=  $common->load_right_content();
//         }
        //var_dump($_SERVER);

        $post_icons = $this->html_post_icons();
        //var_dump($post_icons);exit();
        //-----------------------------------------
        // POLL BOX
        //-----------------------------------------
//        $poll_box = "";2
//
//        if ( $this->can_add_poll )
//        {
//                //-----------------------------------------
//                // Did someone hit preview / do we have
//                // post info?
//                //-----------------------------------------
//
//                $poll_questions = "";
//                $poll_question  = "";
//                $poll_votes		= "";
//                $poll_choices   = "";
//                $show_open      = 0;
//                $poll_only		= "";
//                $poll_multi		= "";
//
//                if ( isset($_POST['question']) AND is_array( $_POST['question'] ) and count( $_POST['question'] ) )
//                {
//                        foreach( $_POST['question'] as $id => $question )
//                        {
//                                $poll_questions .= "\t{$id} : '".str_replace( "'", '&#39;', $question )."',\n";
//                        }
//
//                        $poll_question = $this->ipsclass->input['poll_question'];
//                        $show_open     = 1;
//                }
//
//                if ( isset($_POST['multi']) AND is_array( $_POST['multi'] ) and count( $_POST['multi'] ) )
//                {
//                        foreach( $_POST['multi'] as $id => $checked )
//                        {
//                                $poll_multi .= "\t{$id} : '{$checked}',\n";
//                        }
//                }			
//
//                if ( isset($_POST['choice']) AND is_array( $_POST['choice'] ) and count( $_POST['choice'] ) )
//                {
//                        foreach( $_POST['choice'] as $id => $choice )
//                        {
//                                $poll_choices .= "\t'{$id}' : '".str_replace( "'", '&#39;', $choice )."',\n";
//                        }
//                }
//
//                $poll_only = 0;
//
//                if( $this->ipsclass->vars['ipb_poll_only'] AND isset($this->ipsclass->input['poll_only']) AND $this->ipsclass->input['poll_only'] == 1 )
//                {
//                        $poll_only = "checked='checked'";
//                }
//
//                //-----------------------------------------
//                // Trim off trailing commas (Safari hates it)
//                //-----------------------------------------
//
//                $poll_questions = preg_replace( "#,(\n)?$#", "\\1", $poll_questions );
//                $poll_multi 	= preg_replace( "#,(\n)?$#", "\\1", $poll_multi );
//                $poll_choices   = preg_replace( "#,(\n)?$#", "\\1", $poll_choices );
//
//                $poll_box = $this->ipsclass->compiled_templates['skin_post']->poll_box( $this->max_poll_questions, $this->max_poll_choices_per_question, $poll_questions, $poll_choices, $poll_votes, $show_open, $poll_question, 0, $poll_multi, $poll_only );
//        }
        //-----------------------------------------
        // UPLOAD BOX
        //-----------------------------------------

        $upload_field = $this->can_upload ? $this->html_build_uploads($this->post_key, 'new') : '';

        $this->output = str_replace("<!--START TABLE-->", $start_table, $this->output);
        $this->output = str_replace("<!--NAME FIELDS-->", $name_fields, $this->output);
        $this->output = str_replace("<!--POST BOX-->", $post_box, $this->output);
//        //$this->output = str_replace( "<!--POLL BOX-->"    , $poll_box     , $this->output );
        $this->output = str_replace("<!--POST ICONS-->", $post_icons, $this->output);
        $this->output = str_replace("<!--UPLOAD FIELD-->", $upload_field, $this->output);
//        //$this->output = str_replace( "<!--MOD OPTIONS-->" , $mod_options  , $this->output );
        $this->output = str_replace("<!--END TABLE-->", $end_form, $this->output);
        $this->output = str_replace("<!--TOPIC TITLE-->", $topic_title, $this->output);
        $this->output = str_replace("<!--FORUM RULES-->", $this->ipsclass->print_forum_rules($this->forum), $this->output);
        //-----------------------------------------
        // Add in siggy buttons and such
        //-----------------------------------------

        $this->html_checkboxes('new', 0, $this->forum['id']);

        $this->title = $this->ipsclass->lang['posting_new_topic'];
        $var = array('status'=>1);
        $this->show_post_navigation($var);
        //-----------------------------------------
        // Reset multi-quote cookie
        //-----------------------------------------

        if (((isset($this->obj['post_errors']) AND $this->obj['post_errors']) || $this->obj['preview_post']) && isset ($this->ipsclass->input['diary']) && $this->ipsclass->input['diary'] == "diary") {
           $this->output .= "</div></div>";
           $this->output .=  $common->load_right_content();
        }
        //echo $this->output;exit();
        $this->ipsclass->my_setcookie('mqtids', ',', 0);

        $this->ipsclass->print->add_output($this->output);
        $this->ipsclass->print->do_output(array('TITLE' => $this->ipsclass->vars['board_name'] . " -> " . $this->title,
            'JS' => 1,
            'NAV' => $this->nav,
        ));
    }

}

?>
